home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / if.test < prev    next >
Encoding:
Text File  |  1994-12-18  |  4.1 KB  |  149 lines

  1. # Commands covered:  if
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) if.test 1.7 94/12/17 16:20:01
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. test if-1.1 {taking proper branch} {
  18.     set a {}
  19.     if 0 {set a 1} else {set a 2}
  20.     set a
  21. } 2
  22. test if-1.2 {taking proper branch} {
  23.     set a {}
  24.     if 1 {set a 1} else {set a 2}
  25.     set a
  26. } 1
  27. test if-1.3 {taking proper branch} {
  28.     set a {}
  29.     if 1<2 {set a 1}
  30.     set a
  31. } 1
  32. test if-1.4 {taking proper branch} {
  33.     set a {}
  34.     if 1>2 {set a 1}
  35.     set a
  36. } {}
  37. test if-1.5 {taking proper branch} {
  38.     set a {}
  39.     if 0 {set a 1} else {}
  40.     set a
  41. } {}
  42. test if-1.5 {taking proper branch} {
  43.     set a {}
  44.     if 0 {set a 1} elseif 1 {set a 2} elseif 1 {set a 3} else {set a 4}
  45.     set a
  46. } {2}
  47. test if-1.6 {taking proper branch} {
  48.     set a {}
  49.     if 0 {set a 1} elseif 0 {set a 2} elseif 1 {set a 3} else {set a 4}
  50.     set a
  51. } {3}
  52. test if-1.7 {taking proper branch} {
  53.     set a {}
  54.     if 0 {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} else {set a 4}
  55.     set a
  56. } {4}
  57.  
  58.  
  59. test if-2.1 {optional then-else args} {
  60.     set a 44
  61.     if 0 then {set a 1} elseif 0 then {set a 3} else {set a 2}
  62.     set a
  63. } 2
  64. test if-2.2 {optional then-else args} {
  65.     set a 44
  66.     if 1 then {set a 1} else {set a 2}
  67.     set a
  68. } 1
  69. test if-2.3 {optional then-else args} {
  70.     set a 44
  71.     if 0 {set a 1} else {set a 2}
  72.     set a
  73. } 2
  74. test if-2.4 {optional then-else args} {
  75.     set a 44
  76.     if 1 {set a 1} else {set a 2}
  77.     set a
  78. } 1
  79. test if-2.5 {optional then-else args} {
  80.     set a 44
  81.     if 0 then {set a 1} {set a 2}
  82.     set a
  83. } 2
  84. test if-2.6 {optional then-else args} {
  85.     set a 44
  86.     if 1 then {set a 1} {set a 2}
  87.     set a
  88. } 1
  89. test if-2.7 {optional then-else args} {
  90.     set a 44
  91.     if 0 then {set a 1} else {set a 2}
  92.     set a
  93. } 2
  94. test if-2.8 {optional then-else args} {
  95.     set a 44
  96.     if 0 then {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} {set a 4}
  97.     set a
  98. } 4
  99.  
  100. test if-3.1 {return value} {
  101.     if 1 then {set a 22; concat abc}
  102. } abc
  103. test if-3.2 {return value} {
  104.     if 0 then {set a 22; concat abc} elseif 1 {concat def} {concat ghi}
  105. } def
  106. test if-3.3 {return value} {
  107.     if 0 then {set a 22; concat abc} else {concat def}
  108. } def
  109. test if-3.4 {return value} {
  110.     if 0 then {set a 22; concat abc}
  111. } {}
  112. test if-3.5 {return value} {
  113.     if 0 then {set a 22; concat abc} elseif 0 {concat def}
  114. } {}
  115.  
  116. test if-4.1 {error conditions} {
  117.     list [catch {if} msg] $msg
  118. } {1 {wrong # args: no expression after "if" argument}}
  119. test if-4.2 {error conditions} {
  120.     list [catch {if {[error "error in condition"]}} msg] $msg
  121. } {1 {error in condition}}
  122. test if-4.3 {error conditions} {
  123.     list [catch {if 2} msg] $msg
  124. } {1 {wrong # args: no script following "2" argument}}
  125. test if-4.4 {error conditions} {
  126.     list [catch {if 2 then} msg] $msg
  127. } {1 {wrong # args: no script following "then" argument}}
  128. test if-4.5 {error conditions} {
  129.     list [catch {if 2 the} msg] $msg
  130. } {1 {invalid command name "the"}}
  131. test if-4.6 {error conditions} {
  132.     list [catch {if 2 then {[error "error in then clause"]}} msg] $msg
  133. } {1 {error in then clause}}
  134. test if-4.7 {error conditions} {
  135.     list [catch {if 0 then foo elseif} msg] $msg
  136. } {1 {wrong # args: no expression after "elseif" argument}}
  137. test if-4.8 {error conditions} {
  138.     list [catch {if 0 then foo elsei} msg] $msg
  139. } {1 {invalid command name "elsei"}}
  140. test if-4.9 {error conditions} {
  141.     list [catch {if 0 then foo elseif 0 bar else} msg] $msg
  142. } {1 {wrong # args: no script following "else" argument}}
  143. test if-4.10 {error conditions} {
  144.     list [catch {if 0 then foo elseif 0 bar els} msg] $msg
  145. } {1 {invalid command name "els"}}
  146. test if-4.11 {error conditions} {
  147.     list [catch {if 0 then foo elseif 0 bar else {[error "error in else clause"]}} msg] $msg
  148. } {1 {error in else clause}}
  149.